from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-22 14:03:13.920732
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 22, Jan, 2022
Time: 14:03:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7939
Nobs: 544.000 HQIC: -48.2271
Log likelihood: 6336.27 FPE: 8.60008e-22
AIC: -48.5051 Det(Omega_mle): 7.29970e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360027 0.070214 5.128 0.000
L1.Burgenland 0.103616 0.042644 2.430 0.015
L1.Kärnten -0.113249 0.022086 -5.128 0.000
L1.Niederösterreich 0.189941 0.088892 2.137 0.033
L1.Oberösterreich 0.130133 0.087795 1.482 0.138
L1.Salzburg 0.260189 0.045004 5.781 0.000
L1.Steiermark 0.026776 0.059438 0.450 0.652
L1.Tirol 0.104374 0.047889 2.180 0.029
L1.Vorarlberg -0.074044 0.042312 -1.750 0.080
L1.Wien 0.019089 0.078102 0.244 0.807
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060515 0.152835 0.396 0.692
L1.Burgenland -0.043123 0.092824 -0.465 0.642
L1.Kärnten 0.040433 0.048075 0.841 0.400
L1.Niederösterreich -0.206036 0.193492 -1.065 0.287
L1.Oberösterreich 0.456318 0.191105 2.388 0.017
L1.Salzburg 0.284656 0.097961 2.906 0.004
L1.Steiermark 0.113044 0.129378 0.874 0.382
L1.Tirol 0.306296 0.104239 2.938 0.003
L1.Vorarlberg 0.021239 0.092101 0.231 0.818
L1.Wien -0.024010 0.170006 -0.141 0.888
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197364 0.035804 5.512 0.000
L1.Burgenland 0.090468 0.021745 4.160 0.000
L1.Kärnten -0.007345 0.011262 -0.652 0.514
L1.Niederösterreich 0.235951 0.045329 5.205 0.000
L1.Oberösterreich 0.167850 0.044770 3.749 0.000
L1.Salzburg 0.039107 0.022949 1.704 0.088
L1.Steiermark 0.024436 0.030309 0.806 0.420
L1.Tirol 0.081260 0.024420 3.328 0.001
L1.Vorarlberg 0.054713 0.021576 2.536 0.011
L1.Wien 0.117831 0.039827 2.959 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118643 0.035987 3.297 0.001
L1.Burgenland 0.043408 0.021857 1.986 0.047
L1.Kärnten -0.013881 0.011320 -1.226 0.220
L1.Niederösterreich 0.172611 0.045560 3.789 0.000
L1.Oberösterreich 0.336174 0.044998 7.471 0.000
L1.Salzburg 0.099997 0.023066 4.335 0.000
L1.Steiermark 0.108784 0.030464 3.571 0.000
L1.Tirol 0.090595 0.024545 3.691 0.000
L1.Vorarlberg 0.059485 0.021686 2.743 0.006
L1.Wien -0.016129 0.040030 -0.403 0.687
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120441 0.067930 1.773 0.076
L1.Burgenland -0.044993 0.041257 -1.091 0.275
L1.Kärnten -0.045089 0.021368 -2.110 0.035
L1.Niederösterreich 0.141885 0.086001 1.650 0.099
L1.Oberösterreich 0.166966 0.084940 1.966 0.049
L1.Salzburg 0.281645 0.043541 6.469 0.000
L1.Steiermark 0.062125 0.057505 1.080 0.280
L1.Tirol 0.153867 0.046331 3.321 0.001
L1.Vorarlberg 0.094807 0.040936 2.316 0.021
L1.Wien 0.072073 0.075562 0.954 0.340
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.088448 0.052834 1.674 0.094
L1.Burgenland 0.019827 0.032089 0.618 0.537
L1.Kärnten 0.052668 0.016619 3.169 0.002
L1.Niederösterreich 0.190509 0.066889 2.848 0.004
L1.Oberösterreich 0.329648 0.066064 4.990 0.000
L1.Salzburg 0.036861 0.033865 1.088 0.276
L1.Steiermark -0.001855 0.044726 -0.041 0.967
L1.Tirol 0.122354 0.036035 3.395 0.001
L1.Vorarlberg 0.064790 0.031839 2.035 0.042
L1.Wien 0.098157 0.058770 1.670 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172508 0.064041 2.694 0.007
L1.Burgenland 0.006446 0.038895 0.166 0.868
L1.Kärnten -0.065007 0.020144 -3.227 0.001
L1.Niederösterreich -0.108038 0.081077 -1.333 0.183
L1.Oberösterreich 0.213090 0.080077 2.661 0.008
L1.Salzburg 0.051374 0.041048 1.252 0.211
L1.Steiermark 0.252117 0.054212 4.651 0.000
L1.Tirol 0.497539 0.043678 11.391 0.000
L1.Vorarlberg 0.066022 0.038592 1.711 0.087
L1.Wien -0.082185 0.071236 -1.154 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159720 0.070787 2.256 0.024
L1.Burgenland -0.006872 0.042992 -0.160 0.873
L1.Kärnten 0.062454 0.022266 2.805 0.005
L1.Niederösterreich 0.178561 0.089618 1.992 0.046
L1.Oberösterreich -0.066050 0.088512 -0.746 0.456
L1.Salzburg 0.205579 0.045372 4.531 0.000
L1.Steiermark 0.137094 0.059923 2.288 0.022
L1.Tirol 0.056437 0.048280 1.169 0.242
L1.Vorarlberg 0.144395 0.042657 3.385 0.001
L1.Wien 0.131877 0.078740 1.675 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395278 0.041351 9.559 0.000
L1.Burgenland -0.003420 0.025114 -0.136 0.892
L1.Kärnten -0.020560 0.013007 -1.581 0.114
L1.Niederösterreich 0.203516 0.052351 3.888 0.000
L1.Oberösterreich 0.241707 0.051705 4.675 0.000
L1.Salzburg 0.033504 0.026504 1.264 0.206
L1.Steiermark -0.017836 0.035004 -0.510 0.610
L1.Tirol 0.086857 0.028203 3.080 0.002
L1.Vorarlberg 0.051194 0.024919 2.054 0.040
L1.Wien 0.033465 0.045996 0.728 0.467
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034716 0.101565 0.167179 0.135961 0.089750 0.082327 0.031045 0.212643
Kärnten 0.034716 1.000000 -0.026774 0.133048 0.047547 0.084633 0.445226 -0.069433 0.093338
Niederösterreich 0.101565 -0.026774 1.000000 0.308984 0.126372 0.266253 0.068608 0.157103 0.281736
Oberösterreich 0.167179 0.133048 0.308984 1.000000 0.216081 0.292905 0.171920 0.135915 0.235371
Salzburg 0.135961 0.047547 0.126372 0.216081 1.000000 0.128158 0.088512 0.105318 0.127731
Steiermark 0.089750 0.084633 0.266253 0.292905 0.128158 1.000000 0.137529 0.104406 0.029600
Tirol 0.082327 0.445226 0.068608 0.171920 0.088512 0.137529 1.000000 0.064235 0.151465
Vorarlberg 0.031045 -0.069433 0.157103 0.135915 0.105318 0.104406 0.064235 1.000000 -0.004481
Wien 0.212643 0.093338 0.281736 0.235371 0.127731 0.029600 0.151465 -0.004481 1.000000